package com.qc.controller.web;

import java.util.List;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import net.sf.json.JSONObject;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import com.qc.entity.UserVerifyEntityVo;
import com.qc.pageUtil.page.page.Page;
import com.qc.pageUtil.page.page.PageModel;
import com.qc.pageUtil.page.page.PageModelList;
import com.qc.pageUtil.page.vo.NewsAndNav;
import com.qc.service.UserService;

@Controller
@RequestMapping("/web")
public class WebVerifyController {

    @Resource
    private UserService userService;
    
    /**
     * 审核管理首页
     * @return
     */
    @RequestMapping(value = "/toVerifyIndex", produces = "text/html;charset=UTF-8")
    public ModelAndView toVerifyIndex() {
        ModelAndView mav = new ModelAndView("/verify/shenhe");
        return mav;
    }
    
    @SuppressWarnings({ "rawtypes", "unchecked" })
    @RequestMapping(value = "/toListAllVerify", method = RequestMethod.POST, produces = "text/html;charset=UTF-8")
    @ResponseBody
    public String toListAllVerify(HttpServletRequest request) {
        
        String mobile = request.getParameter("mobile");
        
        String userRole = request.getParameter("vtype");
        
        String sex = request.getParameter("sex");
        
        //当前页面
        int pageNo = Integer.parseInt(request.getParameter("pageNo"));
        //每页显示多少条
        int pageSize = Integer.parseInt(request.getParameter("pageSize"));
        
        //根据条件总数
        int recordCount = userService.getListVerifyCount(mobile, userRole, sex);
        
        //根据条件查询当前页数据
        List<UserVerifyEntityVo> list = userService.getListAllVerify(mobile, userRole, sex, pageNo, pageSize);
        
        //分页查询公共类
        Page<UserVerifyEntityVo> page = new Page<UserVerifyEntityVo>(pageNo, recordCount,pageSize);
        page.setList(list);//设置结果集  
        PageModelList<UserVerifyEntityVo> pageModel = new PageModelList<UserVerifyEntityVo>(page, "#", PageModel.NUM_MODEL,"doPage","1");//设置页码显示类型  
        //4 组装带翻页导航功能的对象
        NewsAndNav  objs = new NewsAndNav(list, pageModel.getPageModel());
        
        return JSONObject.fromObject(objs).toString();
        
    }
    
    
    /**
     * 审核管理详细
     * @return
     */
    @RequestMapping(value = "/toVerifyInformIndex", produces = "text/html;charset=UTF-8")
    public ModelAndView toVerifyInformIndex(HttpServletRequest request) {
        ModelAndView mav = new ModelAndView("/verify/shenhe_chakan");
        
        String id = request.getParameter("id");
        UserVerifyEntityVo verifyEntityVo = userService.getVerifyId(id);
        
        mav.addObject("verifyEntityVo",verifyEntityVo);
        
        return mav;
    }
    
    @RequestMapping(value = "/toUpdateVerify")
    @ResponseBody
    public int toUpdateVerify(HttpServletRequest request) {
        
        String id = request.getParameter("id");
        String vType = request.getParameter("vType");
        String describe = request.getParameter("describe");
        int flag = userService.updateVType(vType, id,describe);
        return flag;
    }
    
}
